//
//  shenghuotongWebviewController.m
//  TiscoNews
//
//  Created by love on 14-5-23.
//
//

#import "shenghuotongWebviewController.h"
#import "MBProgressHUD.h"
#import <ReactiveCocoa.h>


@interface shenghuotongWebviewController ()

@property (nonatomic, strong) MBProgressHUD *HUD;
@end

@implementation shenghuotongWebviewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        self.view.frame = [[UIScreen mainScreen] bounds];
        self.rightButton.hidden = YES;
        [self.leftButton setImage:[UIImage imageNamed:@"icon_back@2x.png"] forState:UIControlStateNormal];
        [[self.leftButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            [self.navigationController popViewControllerAnimated: YES];
        }];

        
       // if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
       // {
       //     self.edgesForExtendedLayout = UIRectEdgeNone;
       // }
      
        
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,self.navBar.frame.size.height, 320, self.view.frame.size.height-self.navBar.frame.size.height)];
        
       
        //_webView.scalesPageToFit = YES;
        
        _webView.delegate = self;
        
        for (UIView *subView in [_webView subviews]) {
            if ([subView isKindOfClass:[UIScrollView class]]) {
                UIScrollView *scrollView = (UIScrollView *)subView;
                scrollView.bounces = NO;
            }
        }
        
        [self.view addSubview:_webView];
        
        UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] init];
        swipe.direction = UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:swipe];
        [[swipe rac_gestureSignal] subscribeNext:^(id x) {
            [self.navigationController popViewControllerAnimated:YES];
        }];
        
        _HUD = [[MBProgressHUD alloc] initWithView:self.view];
        [self.view addSubview:_HUD];
        _HUD .labelText = @"正在加载数据";
        
    }
    return self;
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [_HUD show:YES];
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_HUD hide:YES];
    
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    
}

- (void)setUrl:(NSURL *)url
{
    _url = url;
    [_webView loadRequest:[NSURLRequest requestWithURL:_url]];
    
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.webView stopLoading];
    self.webView = nil;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
